package org.smile.util;

import java.beans.PropertyDescriptor;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class ClassTypeUtils {
	/**
	 * 判断是否是基础数据类型
	 * @param type
	 * @return
	 */
	public static boolean isBasicType(Class type){
		if(type.toString().indexOf(".")>0){
			return false;
		}else{
			return true;
		}
	}
	
	
	public static Class[] getGeneric(PropertyDescriptor prop){
		//泛型
		Class[] generic=null;
		try{
			Type type=prop.getReadMethod().getGenericReturnType();
				if(ParameterizedType.class.isAssignableFrom(type.getClass())){
				ParameterizedType pt=(ParameterizedType)type;
				Type[] genericType=pt.getActualTypeArguments();
				generic=new Class[genericType.length];
				for(int j=0;j<genericType.length;j++){
					generic[j]=(Class)genericType[j];
				}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return generic;
	}
}
